<?php

namespace app\common\model;

use wechat\Factory;

class WechatModel
{

  private $wechat;

  /**
   * 初始化
   * WechatModel constructor.
   */
  public function __construct()
  {
    $this->wechat = Factory::officialAccount();
  }

  /**
   * 生成短网址
   * @param $url
   * @return mixed
   */
  public function shortUrl($url){
    $result = $this->wechat->url->shorten($url);
    if($result['errcode']==0) return $result['short_url'];
    abort(500,$result['errmsg']);
  }

}
